<?php
$tipo = getParam("tipoconsulta");
$codigo = getParam("codigo");
$fini = getParam("fini");
if (!isEmpty($fini)) {
    $fini = explode("/", $fini);
    $fini = $fini[1] . "/" . $fini[0] . "/" . $fini[2];
}
$ffin = getParam("fini");
if (!isEmpty($ffin)) {
    $ffin = explode("/", $ffin);
    $ffin = $ffin[1] . "/" . $ffin[0] . "/" . $ffin[2];
}
$w = (isEmpty($tipo) || $tipo == "3") ? "" : " AND c.TIPO='$tipo'";
$w = isEmpty($codigo) ? $w : "$w AND c.FK_ESTUDIANTE ";
$w = isEmpty($fini) ? $w : "$w AND pp.FECHA>='$fini'";
$w = isEmpty($ffin) ? $w : "$w AND pp.FECHA<='$ffin'";
$sql = "select c.FK_ESTUDIANTE,c.TIPO tcuenta,c.ID,c.ESTADO,c.FECHA fecha_emision,p.MONTO,f.TIPO 
        forma_pago,pp.FECHA fecha_pago from cllg_academico_cobros c,
      cllg_academico_pagos_detail p,cllg_academico_pagos_formas f,cllg_academico_pagos pp
            where c.ID=p.FK_COBRO_ID and f.FK_PAGO_ID=p.FK_PAGO_ID and pp.ID=f.FK_PAGO_ID $w";
$rs = $this->db->queryToArray($sql);
$_SESSION["replastsql"]=$sql;

$sql = "select SUM(MONTO) TOTAL from ($sql) A";
$rsT = $this->db->queryToArray($sql);
$total = count($rsT) > 0 ? $rsT[0]["TOTAL"] : 0;
$total = isEmpty($total) ? 0 : $total;
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th scope="col">ESTUDIANTE/BENEF</th>
            <th scope="col">TIPO CTA.</th>
            <th scope="col">COBRO</th>
            <th scope="col">FECHA EMISION</th>
            <th scope="col">FECHA PAGO</th>        
            <th scope="col">FORMA PAGO</th>        
            <th scope="col">MONTO</th>        
        </tr>
    </thead>
    <tbody>    
        <?php if (count($rs) > 0) {
            foreach ($rs as $r) { ?>
                <tr>
                    <td><?php echo $r["FK_ESTUDIANTE"] ?></td>
                    <td><?php echo $r["tcuenta"] ?></td>
                    <td><?php echo $r["ID"] ?></td>
                    <td><?php echo date("d/m/Y", strtotime($r["fecha_emision"])) ?></td>
                    <td><?php echo date("d/m/Y", strtotime($r["fecha_pago"])) ?></td>
                    <td><?php echo $r["forma_pago"] ?></td>
                    <td><?php echo number_format($r["MONTO"], 2); ?></td>  

                </tr>
            <?php }
        } else { ?>
            <tr>
                <td colspan="5">No posee informacion!</td>
            </tr>  
        <?php } ?>
    </tbody>
    <tfoot>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <th>Total Cobrado</th>
            <th><?php echo number_format($total, 2); ?></th>
        </tr>
    </tfoot>
</table>
</body>
</html>